﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bunian.Core.BusinessObjects;
using Bunian.Data;

namespace Bunian.Service
{
    public class TenderService : IDisposable
    {
        private NHibernateDataContext _context = null;

        public TenderService()
        {
            _context = new NHibernateDataContext();
        }
      
        public Tender GetTenderById(long TenderId)
        {
            return _context.GetById<Tender>(TenderId);
        }

        public Contact CreateTender()
        {
            Contact newContact = new Contact();

            _context.Save(newContact);

            return newContact;
        }

        public void SaveContact(Contact ContactToBeSaved)
        {
            if (null != ContactToBeSaved && ContactToBeSaved.Id != 0)
            {
                _context.Save(ContactToBeSaved);
            }
        }

        public IList<T> GetAllBasedOnType<T>()// where T : class, new()
        {
            return _context.GetAll<T>();
        }

        public Orphan TestInheritance()
        {
            return (Orphan)_context.GetById<Tender>((long)8);
        }

        #region IDisposable Members

        public void Dispose()
        {
            _context.Dispose();
        }

        #endregion
    }
}
